package systems.database.query.condition;

import java.util.HashMap;
import java.util.Set;
import java.util.Map.Entry;

/**
 * Provides mechanisms to build condition according to the following grammar :
 * condition := expression [JunctionEnum expression]*
 * @author Baptiste Legrand & Benjamin Orman
 *
 */
public class Condition {
	private Expression expression1;
	private HashMap<Expression, JunctionEnum> nextExpressionsList;

	public Condition()
	{
	  this.nextExpressionsList = new HashMap<Expression, JunctionEnum>();
	}
	
	public Condition(Expression expr1)
	{
		this.expression1 = expr1;
    this.nextExpressionsList = new HashMap<Expression, JunctionEnum>();
	}
	
	public void setFirstExpression(Expression expr1)
	{
	  this.expression1 = expr1;
	}
	public void addNextExpression(JunctionEnum junction, Expression expr2)
	{
	  this.nextExpressionsList.put(expr2, junction);
	}

	public String getConditionString()
	{
	  Set<Entry<Expression, JunctionEnum>> entrySet = this.nextExpressionsList.entrySet();
		String condition="";
		condition+= this.expression1.getExpressionString();
		for(Entry<Expression, JunctionEnum> set : entrySet)
			condition+=" "+set.getValue()+" "+set.getKey().getExpressionString();
		return condition;
	}
	
	/** Getter **/
	
	public Expression getExpression1()
	{
		return this.expression1;
	}
}